﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>GroupAdd - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The GroupAdd function adds a window specification to a window group, creating the group if necessary." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>GroupAdd</h1>

<p>Adds a window specification to a window group, creating the group if necessary.</p>

<pre class="Syntax"><span class="func">GroupAdd</span> GroupName <span class="optional">, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>GroupName</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The name of the group to which to add this window specification. If the group doesn't exist, it will be created. Group names are not case sensitive.</p>
  </dd>

  <dt>WinTitle</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
    <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
  </dd>

  <dt>WinText</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON at the time that <a href="GroupActivate.htm">GroupActivate</a>, <a href="GroupDeactivate.htm">GroupDeactivate</a>, and <a href="GroupClose.htm">GroupClose</a> are used.</p>
  </dd>

  <dt>ExcludeTitle</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>标题中含有此参数值的窗口将被排除.</p>
  </dd>

  <dt>ExcludeText</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>文本中含有此参数值的窗口将被排除.</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>Each use of this function adds a new rule to a group. In other words,  a group consists of a set of criteria rather than a fixed list of windows. Later, when a group is used by a function such as <a href="GroupActivate.htm">GroupActivate</a>, each window on the desktop is checked against each of these criteria. If a window matches one of the criteria in the group, it is considered a match.</p>
<p>Although <a href="SetTitleMatchMode.htm">SetTitleMatchMode</a> and <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> do not directly affect the behavior of this function, they do affect the other group functions such as <a href="GroupActivate.htm">GroupActivate</a> and <a href="GroupClose.htm">GroupClose</a>. They also affect the use of ahk_group in any other function's <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
<p>A window group is typically used to bind together a collection of related windows, which is useful for tasks that involve many related windows, or an application that owns many subwindows. 例如, if you frequently work with many instances of a graphics program or text editor, you can use <a href="GroupActivate.htm">GroupActivate</a> on a hotkey to visit each instance of that program, one at a time, without having to use alt-tab or task bar buttons to locate them.</p>
<p>Since the entries in each group need to be added only once, this function is typically used during <a href="../Scripts.htm#auto">script startup</a>. Attempts to add duplicate entries to a group are ignored.</p>
<p>To include <u>all</u> windows in a group (except the special Program Manager window), use this example:</p>
<pre>GroupAdd "AllWindows"</pre>
<p>All windowing functions can operate upon a window group by specifying <code>ahk_group MyGroupName</code> for the <em>WinTitle</em> parameter. The functions <a href="WinMinimize.htm">WinMinimize</a>, <a href="WinMaximize.htm">WinMaximize</a>, <a href="WinRestore.htm">WinRestore</a>, <a href="WinHide.htm">WinHide</a>, <a href="WinShow.htm">WinShow</a>, <a href="WinClose.htm">WinClose</a>, and <a href="WinKill.htm">WinKill</a> will act upon <strong>all</strong> the group's windows. To instead act upon only the topmost window, follow this example:</p>
<pre>WinHide &quot;ahk_id &quot; . WinExist(&quot;ahk_group <strong>MyGroup</strong>&quot;)</pre>
<p>By contrast, the other window functions such as <a href="WinActivate.htm">WinActivate</a> and <a href="WinExist.htm">WinExist</a> will operate only upon the topmost window of the group.</p>
<h2 id="Related">相关</h2>
<p><a href="GroupActivate.htm">GroupActivate</a>, <a href="GroupDeactivate.htm">GroupDeactivate</a>, <a href="GroupClose.htm">GroupClose</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExIE">
<p><a href="#ExIE">#1</a></p>
<pre><em>; 在脚本顶部的自动执行段:</em>
GroupAdd "MSIE", "ahk_class IEFrame" <em>; 只添加 Internet Explorer 窗口到该组.</em>
return <em>; 自动执行段的结束.</em>

<em>; 设置一个热键激活该组, 它会遍历
; 打开的所有 MSIE 窗口, 每次一个
; (即每次使用热键时激活一个窗口).</em>
Numpad1::GroupActivate "MSIE", "r"</pre>
</div>

<div class="ex" id="ExOutlook">
  <p><a href="#ExOutlook">#2</a>: 这是用于 MS Outlook 2002 的更复杂的组.<p>
  <pre><em>; 在脚本顶部的自动执行段:</em>
SetTitleMatchMode 2 
GroupAdd "mail", "Message - Microsoft Word" <em>; This is for mails currently being composed</em>
GroupAdd "mail", "- Message (" <em>; 用于已打开的项目
; 需要附加文本以避免激活错误窗口:</em>
GroupAdd "mail", "Advanced Find", "Sear&amp;ch for the word(s)"
GroupAdd "mail", , "Recurrence:"
GroupAdd "mail", "Reminder"
GroupAdd "mail", "- Microsoft Outlook"
return  <em>; 自动执行段的结束.</em>

Numpad5::GroupActivate "mail" <em>; 设置一个热键用于激活每个 Outlook 窗口(每次一个).</em></pre>
</div>

</body>
</html>